#ifndef __PARSER_H
#define __PARSER_H
#include "__dcc.tbl.h" /* Parsing table */		
#include "__cctype.h"

/* 
   Caution : if function name size is loger than 10, u-code has an error. 
             Fix me this limitation later July 28, 2008
*/

/* About symbolTable */
void initSymbolTable(void);
int insert(char * name, int typeSpecifier, int typeQualifier, int base, int offset, int width, int initialValue);
void setBlock(int base);
void resetBlock(void);
int lookup(char *name);
int hash(char *symbolName);

/* About scanner() */
struct tokenType scanner(void);
int getIntNum(char firstCharacter);
int hexValue(char ch);
void lexicalError(int n);
int superLetter(char ch);
int superLetterOrDigit(char ch);

/* About parser() */
Node *parser(void);
void printToken(struct tokenType token);
void dumpStack(void);
void errorRecovery(void);
int meaningfulToken(struct tokenType token);
void printTree(Node *pt, int indent);
void printNode(Node *pt, int indent);
Node *buildNode(struct tokenType token);
Node *buildTree(int nodeNumber, int rhsLength);

/* About Code generation : main */
void codeGen(Node *ptr);
void processDeclaration(Node *ptr);
void processDeclarationInFunc(Node *ptr);
void processSimpleVariable(Node *ptr, int typeSpecifier, int typeQualifier);
void processArrayVariable(Node *ptr, int typeSpecifier, int typeQaulifier);
void processArrayVariableInFunc(Node *ptr, int typeSpecifier, int typeQualifier);
void processOperator(Node *ptr);
int checkPredefined(Node *p);
void processStatement(Node *ptr);
void processCondition(Node *ptr);
int typeSize(int typeSpecifier);
void processFuncHeader(Node *ptr);
void processFunction(Node *ptr);
int processLocalSize(Node *ptr);
int isOperation(Node *ptr);

/* About Code generation : emit instruction to files */
void genLabel(char *label);
void emit0(int instr);
void emit1(int instr, int operand1);
void emit2(int instr, int operand1, int operand2);
void emit3(int instr, int operand1, int operand2, int operand3);
void emit_proc(char *functionName, int proc, int procLocalSize, int base, int lexical_level);
void emitLabel(char *label);
void emitJump(int instr, char *dest);
void emit_rv(Node *ptr); // load data const? var:array choose itself

#endif
